export const isIpx = () => {
    const sysInfo = wx.getSystemInfoSync()
    const { model } = sysInfo
    // console.log(sysInfo, '===手机型号===')
    let arr = ['iPhone X', 'iPhone XS', 'iPhone XS Max', 'iPhone XR']
    const newArr = ['iPhone 11', 'iPhone 12', 'iPhone 13', 'unknown', 'iPhone 14']
    let isIpx = false
    arr = [...arr, ...newArr]
    arr.forEach(item => {
      if (model.includes(item)) {
        isIpx = true
      }
    })
    return isIpx
  }
  
  export const getAge = strBirthday => {
    let returnAge
    let strBirthdayArr = strBirthday.split('-')
    let birthYear = strBirthdayArr[0]
    let birthMonth = strBirthdayArr[1]
    let birthDay = strBirthdayArr[2]
    let d = new Date()
    let nowYear = d.getFullYear()
    let nowMonth = d.getMonth() + 1
    let nowDay = d.getDate()
    if (nowYear == birthYear) {
      returnAge = 0 //同年则为0岁
    } else {
      let ageDiff = nowYear - birthYear //年之差
      if (ageDiff > 0) {
        if (nowMonth == birthMonth) {
          let dayDiff = nowDay - birthDay //日之差
          if (dayDiff < 0) {
            returnAge = ageDiff - 1
          } else {
            returnAge = ageDiff
          }
        } else {
          let monthDiff = nowMonth - birthMonth //月之差
          if (monthDiff < 0) {
            returnAge = ageDiff - 1
          } else {
            returnAge = ageDiff
          }
        }
      } else {
        returnAge = -1 //返回-1 表示出生日期输入错误 晚于今天
      }
    }
    return returnAge // 返回周岁年龄
  }
  
  function type(obj) {
    // 深拷贝
    const toString = Object.prototype.toString
    const map = {
      '[object Boolean]': 'boolean',
      '[object Number]': 'number',
      '[object String]': 'string',
      '[object Function]': 'function',
      '[object Array]': 'array',
      '[object Date]': 'date',
      '[object RegExp]': 'regExp',
      '[object Undefined]': 'undefined',
      '[object Null]': 'null',
      '[object Object]': 'object',
    }
    return map[toString.call(obj)]
  }
  
  export function cloneDeep(data) {
    // 深拷贝
    const t = type(data)
    let o
    let i
    let ni
    if (t === 'array') {
      o = []
    } else if (t === 'object') {
      o = {}
    } else {
      return data
    }
    if (t === 'array') {
      for (i = 0, ni = data.length; i < ni; i++) {
        o.push(cloneDeep(data[i]))
      }
      return o
    } else if (t === 'object') {
      // eslint-disable-next-line guard-for-in
      for (i in data) {
        o[i] = cloneDeep(data[i])
      }
      return o
    }
  }